package org.compression.services.imp;

import java.util.UUID;

import org.compression.mapper.AduioAttrMapper;
import org.compression.mapper.AudioContentMapper;
import org.compression.services.AudioContentService;
import org.compression.services.BaseService;
import org.compression.util.RedisUtil;
import org.model.auth.PageUser;
import org.model.business.AduioAttr;
import org.model.business.AudioContent;
import org.model.comm.Page;
import org.model.comm.UpdateModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AudioContentServiceImp implements AudioContentService {

	@Autowired
	AudioContentMapper mBookMagamentMapper;

	@Autowired
	RedisUtil	mRedisUtil;
	
	@Override
	public Object getMember(Page mPage) {
		PageUser m=new PageUser();
		Object date=(Object) mRedisUtil.get(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		System.out.println(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		if(date!=null) {
			return date;
		}else {
			m.setMember(mBookMagamentMapper.getPageAudioContent(mPage));
			m.setTotal(mBookMagamentMapper.getTotal());
		//	mRedisUtil.set(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize(), m);
		}
		return m;
	}

	

	@Override
	public Object add(UpdateModel mBookMagament) {
		Page mPage =mBookMagament.getmPage();
		mRedisUtil.del(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		/*String uuid=UUID.randomUUID().toString();
		if(mBookMagamentMapper.selectUUID(uuid).size()<=0) {
		}else {
			 uuid=UUID.randomUUID().toString();
		}
		((AudioContent) mBookMagament.getmBookMagament()).setUuid(uuid);*/
		return mBookMagamentMapper.insertSelective((AudioContent) mBookMagament.getmBookMagament());
		
	}



	@Override
	public Object selectName(AudioContent mBookMagaments) {
		return mBookMagamentMapper.selectName(mBookMagaments);
	}



	@Override
	public void deleteByPrimaryKey(UpdateModel<AudioContent> mAddModel) {
		Page mPage =mAddModel.getmPage();
		mRedisUtil.del(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		mBookMagamentMapper.deleteByPrimaryKey(mAddModel.getmBookMagament().getId());
		
	}



	@Override
	public void updateByPrimaryKeySelective(UpdateModel<AudioContent> mAddModel) {
		Page mPage =mAddModel.getmPage();
		mRedisUtil.del(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		mBookMagamentMapper.updateByPrimaryKeySelective(mAddModel.getmBookMagament());
	}


	@Override
	public AudioContent selectCreateTime(String createdate) {
		return mBookMagamentMapper.selectCreateTime(createdate);
	}


	@Override
	public void updateByPrimaryKeySelective(AudioContent mAduioAttr) {
		mBookMagamentMapper.updateByPrimaryKeySelective(mAduioAttr);		
	}

	


}
